#ifndef STOPCOND_H_
#define STOPCOND_H_
#include <ctime>
#include "message.h"

using namespace std;

/*
 * This class controls the stopping condition for the compression engine
 * It is contained inside a WorkParameters class and is initiated at startup
 * using command line parameters
 */

class StopCondition {	

private:
	// stop conditions:
	int stop_on_seconds;
	int stop_on_iterations;
	int stop_on_snr;
	
	// condition parameters:
	int stop_seconds;
	struct timespec time_start;
	struct timespec time_current;
	
	int stop_iterations;
	int current_iteration;
	
	double stop_snr; // Sound to Noise Ratio
	double current_snr;

	// message class
	Message* message;
	
public:
	// constructor
	StopCondition(Message* msg);
	// note: we do not need to deallocate anything so we have no destructor
	
	// conditions for stopping 
	void addStopOnSeconds(int seconds);
	void addStopOnSNR(double desired_snr);
	void addStopOnIterations(int iterations);
	
	// called from main engine:
	// 1. iteration functions
	int canBeginNewIteration();
	void startIteration();
	// 2. snr-related functions
	int needToCalculateSNR();
	void finishedIteration(double snr);
	
};


#endif /*STOPCOND_H_*/
